import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    serverUrl: localStorage.getItem('serverUrl'),
    token: localStorage.getItem('TM-TOKEN')
  },
  mutations: {
    setServerUrl(state, val) {
      state.serverUrl = val
    },
    setToken(state, val) {
      state.token = val
    }
  },
  actions: {
    setServerUrl({ commit }, val) {
      localStorage.setItem('serverUrl', val)
      commit('setServerUrl', val)
    },
    setToken({ commit }, val) {
      localStorage.setItem('TM-TOKEN', val)
      commit('setToken', val)
    }
  },
  modules: {
  }
})
